﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Presentation.Module.Setup.Interfaces.ViewModels;
using Presentation.Module.Setup.Interfaces.Services;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;
using System.ComponentModel;

namespace Presentation.Setup.Views
{
    public class AddTaskViewModel : IAddTaskViewModel, INotifyPropertyChanged
    {
        private Module.Setup.Models.Task _CurrentTask;

        public AddTaskViewModel(ISkillsService skillService)
        {
            this.SkillService = skillService;
            
            this.Commit = new DelegateCommand(OnCommit);
            this.Cancel = new DelegateCommand(OnCancel);
        }

        public Module.Setup.Models.Task CurrentTask
        {
            get
            {
                return _CurrentTask;
            }
            set
            {
                _CurrentTask = value;
                RaiseOnPropertyChanged("CurrentTask");
            }
        }
        public Module.Setup.Interfaces.Views.IAddTaskView View { get; set; }

        public ICommand Commit { get; set; }
        public ICommand Cancel { get; set; }

        private void OnCommit()
        {
            this.SkillService.AddTask(this.CurrentTask);
            View.Exit();
        }

        private void OnCancel()
        {
            View.Exit();
        }

        private void RaiseOnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public ISkillsService SkillService { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
